(function () {
    angular.module('app')
        .component('xxToolbarForUser', {
            templateUrl: '/app/toolbars/toolbarForUser/toolbarForUser.html',
            controller: ctrl
        });

    function ctrl($scope,ToolbarForUserFactory,userService,$state) {
        $scope.username = userService.username;
        $scope.isConsultant = userService.isConsultant;
        $scope.consultantId = userService.consultantId;
        // console.log($scope.username,$scope.isConsultant);
        $scope.numberUnanswered = 0;

        // var consultantId = $stateParams.consultantId;
        function getUnAnsweredNumber(consultantId){
            function cb(err, res) {
                if (!err) {
                    $scope.numberUnanswered = res['msg'].length;
                    // console.log($scope.numberUnanswered);
                }
            }
            ToolbarForUserFactory.getUnAnsweredNumber(consultantId, cb);
        }
        getUnAnsweredNumber($scope.consultantId);

        $scope.login = function () {
            $state.go('login')
        };
        $scope.logout = function () {
            userService.removeUser();
            //console.log($scope.username,$scope.isConsultant,'testCOOKIES');
            $state.go('login')
        };
        $scope.register = function () {
            $state.go('register')
        };
        $scope.home = function () {
            $state.go('show.home')
        };
        $scope.question = function () {
            $state.go('show.question')
        };
        $scope.showAllQuestion = function () {
            $state.go('show.show-all-essay')
        };
        $scope.showAllQuestionByConsultantId = function (consultantId) {
            $state.go('show.show-all-essay-by-consultant-id',{consultantId:consultantId})
        };
        $scope.personInfo = function (username) {
            $state.go('show.person-info',{username:username})
        };
        $scope.recharge = function (username) {
            $state.go('show.recharge',{username:username})
        };
        $scope.travel = function () {
            $state.go('show.travel')
        };
        $scope.career = function () {
            $state.go('show.career')
        };
        $scope.gym = function () {
            $state.go('show.gym')
        };
        $scope.iDesign = function () {
            $state.go('show.iDesign')
        };
        $scope.car = function () {
            $state.go('show.car')
        };
        $scope.law = function () {
            $state.go('show.law')
        };
    }
})();
